package cn.wolfcode.controller;


import cn.wolfcode.domain.Destination;
import cn.wolfcode.query.DestinationQuery;
import cn.wolfcode.service.IDestinationService;
import cn.wolfcode.service.IRegionService;
import cn.wolfcode.util.JsonResult;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @Description: 目的地控制器类
 * @Author: 伍家钰
 * @Date: 2020/8/11 18:53
 * @Version: 1.0
 */
@Controller
@RequestMapping("destination")
public class DestinationController {
    @Resource
    private IDestinationService destinationService;
    @Resource
    private IRegionService regionService;

    /**
     * 目的地分页查询
     *
     * @param model
     * @param qo
     * @return
     */
    @RequestMapping("list")
    public Object list(Model model, String parentId, @ModelAttribute("qo") DestinationQuery qo) {
        // 如果id有值则是吐司查询
        Page<Destination> page = destinationService.query(qo);
        model.addAttribute("page", page);
        model.addAttribute("toasts", destinationService.queryToast(qo.getParentId()));
        return "destination/list";
    }

    /**
     * 目的地简介编辑和添加
     *
     * @return :
     */
    @RequestMapping("updateInfo")
    @ResponseBody
    public Object updateInfo(String id, String info) {
        //有内容则添加,没有内容则修改
        destinationService.updateInfo(id, info);
        return JsonResult.success();
    }

    /**
     * 目的地删除
     *
     * @return :
     */
    @RequestMapping("delete")
    @ResponseBody
    public Object delete(String id) {
        destinationService.delete(id);
        return JsonResult.success();
    }

}
